#ifndef _ATOMIC_H_
#define _ATOMIC_H_

#include "def.h"

#if defined ATOMIC_MUTEX
#include "mutex.h"
#endif

#ifdef __cplusplus
extern "C"{
#endif

typedef struct {
#if defined ATOMIC_MUTEX
    mutex_t sync;
#endif
    volatile uint32_t n;
}atomic_t;


void atomic_init(atomic_t *self, uint32_t n);
void atomic_term(atomic_t *self);
uint32_t atomic_inc(atomic_t *self, uint32_t n);
uint32_t atomic_dec(atomic_t *self, uint32_t n);

static inline uint32_t atomic_nums(atomic_t *self)
{
	return atomic_inc(self, 0);
}

#ifdef __cplusplus
}
#endif

#endif
